package kr.hkit.powerjava.chapter24.work2.service;

import java.util.Comparator;
import java.util.Scanner;

import kr.hkit.powerjava.chapter24.work2.dao.InterfaceDao;
import kr.hkit.powerjava.chapter24.work2.vo.Student;

public class StudentService extends ServiceItems<Student> {

	public StudentService(InterfaceDao<Student> dao, Scanner input) {
		super(dao, input);
	}

	@Override
	public Student inputItemInfo(boolean gubun) {
		System.out.println("학번 성명");
		Student std = new Student(input.nextInt(), input.next().trim());
		System.out.println("국어 영어 수학");
		if(gubun) {
			std.setKor(input.nextInt());
			std.setEng(input.nextInt());
			std.setMath(input.nextInt());
		}
		return std;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("1.이름순 정렬 2.성적순 정렬 3.번호순 정렬");
		int res = input.nextInt();
		switch(res) {
			case 1:
				dao.prnItemList(new Comparator<Student>() {

					@Override
					public int compare(Student o1, Student o2) {
						return o1.getStdName().hashCode() - o2.getStdName().hashCode();
					}
				});
				break;
			case 2:
				dao.prnItemList(new Comparator<Student>() {

					@Override
					public int compare(Student o1, Student o2) {
						return o1.getTotal()-o2.getTotal();
					}
				});
				break;
			case 3: 
				dao.prnItemList(new Comparator<Student>() {

					@Override
					public int compare(Student o1, Student o2) {
						return o1.getStdNum() - o2.getStdNum();
					}
				});
		}
		
	}

}
